package edu.ahut.corejava2;

import java.util.Arrays;

/**
 * 对象的（引用）浅拷贝深拷贝
 */
public class ClassDemo2 {
    public static void main(String[] args) {
        int[] a = new int[]{1, 2, 3, 4,};
        int[] b = a;//浅拷贝
        a[0]++;
        System.out.println(b[0]);

        int[] c = new int[a.length];
        for (int i = 0; i < a.length; i++) c[i] = a[i];
        //for(int x:c)x=1;//for_each只能对可迭代对象集合做顺序的只读访问
        System.out.println(Arrays.toString(c));
        a[0]++;
        System.out.println(Arrays.toString(c));


        int[] d = a.clone();//
        System.out.println(Arrays.toString(d));
        a[0]++;
        System.out.println(Arrays.toString(d));


    }
}
